package com.logger;

/**
 * log信息的字符拼接
 * Created by chenxunlin01 on 2016/1/16.
 */

public class LoggerBuilder {

    private Logger log;
    private StringBuilder buf;

    public LoggerBuilder(Logger log) {
        this.log = log;
        buf = new StringBuilder();
    }

    public LoggerBuilder(Logger log, Object msg) {
        this.log = log;
        buf = new StringBuilder();
        buf.append(msg);
    }

    public void info() {
        log.log(Level.INFO, buf.toString());
    }

    public void info(Throwable t) {
        log.log(Level.INFO, buf.toString(), t);
    }

    public void debug() {
        log.log(Level.DEBUG, buf.toString());
    }

    public void debug(Throwable t) {
        log.log(Level.DEBUG, buf.toString(), t);
    }

    public void warn() {
        log.log(Level.WARN, buf.toString());
    }

    public void warn(Throwable t) {
        log.log(Level.WARN, buf.toString(), t);
    }

    public void error() {
        log.log(Level.ERROR, buf.toString());
    }

    public void error(Throwable t) {
        log.log(Level.ERROR, buf.toString(), t);
    }

    public void verbose() {
        log.log(Level.VERBOSE, buf.toString());
    }

    public void verbose(Throwable t) {
        log.log(Level.VERBOSE, buf.toString(), t);
    }

    public void log(Level level) {
        log.log(level, buf.toString());
    }

    public void log(Level level, Throwable t) {
        log.log(level, buf.toString(), t);
    }

    public LoggerBuilder format(String format, Object... objs) {
        buf.append(String.format(format, objs));
        return this;
    }

    public LoggerBuilder append(Object obj) {
        return append(String.valueOf(obj));
    }

    public LoggerBuilder append(String str) {
        buf.append(str);
        return this;
    }

    public LoggerBuilder append(StringBuffer sb) {
        buf.append(sb);
        return this;
    }

    /**
     */
    public LoggerBuilder append(CharSequence s) {
        buf.append(s);
        return this;
    }

    /**
     */
    public LoggerBuilder append(CharSequence s, int start, int end) {
        buf.append(s, start, end);
        return this;
    }

    public LoggerBuilder append(char str[]) {
        buf.append(str);
        return this;
    }

    public LoggerBuilder append(char str[], int offset, int len) {
        buf.append(str, offset, len);
        return this;
    }

    public LoggerBuilder append(boolean b) {
        buf.append(b);
        return this;
    }

    public LoggerBuilder append(char c) {
        buf.append(c);
        return this;
    }

    public LoggerBuilder append(int i) {
        buf.append(i);
        return this;
    }

    public LoggerBuilder append(long lng) {
        buf.append(lng);
        return this;
    }

    public LoggerBuilder append(float f) {
        buf.append(f);
        return this;
    }

    public LoggerBuilder append(double d) {
        buf.append(d);
        return this;
    }
}
